﻿@using DTD.Repositories.Entities
@using DTD.Web.Models
@model List<TaskWithCategoryName>

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@if (Model != null)
{
    <div class="tab-content">
    <div class="task-list">
    <style>
        div.status a{background: url('/Content/checkbox_uncheked.png') no-repeat;display: block;width: 24px; height: 24px;}
        div.status a:hover{background: url('/Content/checkbox_checked.png') no-repeat;display: block;width: 24px; height: 24px;}
        div.status span {background: url('/Content/checkbox_checked2.png') no-repeat;display: block;width: 24px; height: 24px;}
    </style>
    @foreach (var task in Model)
    {
        <div class="task">
            <div class="edit"><a class="dashed" onclick="openEditDialog('@task.Task.Title', '@task.Task.Description', @task.Task.Id, '@task.CategoryName')">Редактировать</a></div>
            @{string taskCliendId = "task_" + task.Task.Id;}
            <div id="@taskCliendId" class="status">
            @if (task.Task.Status == (int)TaskStatuses.NotReady)
            {
                @Ajax.ActionLink(" ", "MarkDone", "Tasks", new {Id = task.Task.Id}, new AjaxOptions {HttpMethod = "Post", OnSuccess = "success(" + task.Task.Id + ")"})
            }
            else
            {
                <span></span>
            }
            </div>
            <div class="title"><a class="dashed" href="#">@task.Task.Title</a></div>
            <p class="description">@task.Task.Description</p> 
        </div>
    }
    </div>
    </div>
    <script type="text/javascript">
        function success(taskId) {
            $("#task_" + taskId).html("<span></span>");
        }
    </script>
}

